<?php

class Category_model extends CI_Model {

	function __construct() {
		parent::__construct();
	}
	
	function get_all_categories(){
		$sql = "SELECT * FROM category";
		$query = $this->db->query($sql);
			
		$data = array();
		if($query->num_rows() > 0){
			foreach ($query->result_array() as $row) {
				$data[] = $row;
			}			
		}
		return $data;
	}
	
	function get_all_sub_categories(){
		$sql = "SELECT * FROM sub_category";
		$query = $this->db->query($sql);
			
		$data = array();
		if($query->num_rows() > 0){
			foreach ($query->result_array() as $row) {
				$data[] = $row;
			}				
		}
		return $data;
	}
		
	function get_categories_and_sub_categories(){
		$categories = get_all_categories();

		foreach ($categories as $key=>$value){
			$categories[$key][] = get_sub_categories($value);
		}
		
		return $categories;
	}
	
	function get_sub_categories($category_id){
		$sql = "SELECT * FROM category where category_id = ?";
		$query = $this->db->query($sql, $category_id);
			
		$data = array();
		if($query->num_rows() > 0){
			foreach ($query->result_array() as $row) {
				$data[] = $row;
			}		
		}
		return $data;
	}
	
}
?>